# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class XLink:
   UNKNOWN = -1

   SIMPLE = 1

   ON_REQUEST = 1

   SHOW_NEW     = 1
   SHOW_REPLACE = 2

   def __init__(self, attrs):
      self.location = attrs.get('xlink:href', '')

      self.setType(attrs.get('xlink:type', 'simple'))
      self.setActuate(attrs.get('xlink:actuate', 'onRequest'))
      self.setShow(attrs.get('xlink:show', 'replace'))

   def getLocation(self):
      return self.location

   def setLocation(self, location):
      location = location.strip()
      self.location = location

   def getType(self):
      return self.typeID

   def setType(self, type):
      type = type.strip()
      if type.lower() == 'simple':
         self.type   = type.lower()
         self.typeID = self.SIMPLE
      else:
         print "WARNING: Unknown XLink type '%s'" % type
         self.type   = 'simple'
         self.typeID = self.SIMPLE

   def getActuate(self):
      return self.actuateID

   def setActuate(self, actuate):
      actuate = actuate.strip()
      if actuate.lower() == 'onrequest':
         self.atuate    = actuate
         self.actuateID = self.ON_REQUEST
      else:
         print "WARNING: Unknown XLink actuate value '%s'" 
         self.atuate    = 'onRequest'
         self.actuateID = self.ON_REQUEST

   def getShow(self):
      return self.showID

   def setShow(self, show):
      show = show.strip()
      if show == 'new':
         self.show   = show
         self.showID = self.SHOW_NEW
      elif show == 'replace':
         self.show   = show
         self.showID = self.SHOW_REPLACE
      else:
         print "WARNING: Unknown XLink show value '%s'" % show
         self.show   = None
         self.showID = None
